﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using WeChat.Common2;

namespace WeChat.Common
{
    public class WechatHelper
    {
        /// <summary>
        /// 开发者模式接入验证
        /// </summary>
        /// <param name="echoStr"></param>
        /// <param name="signature"></param>
        /// <param name="timestamp"></param>
        /// <param name="nonce"></param>
        /// <returns></returns>
        public static bool UrlVerify(string echoStr, string signature, string timestamp, string nonce)
        {
            
            string token = "weixin";
            ApplicationLog.Write("接收微信接入验证参数：token = " + token + ";timestamp = " + timestamp + ";nonce = " + nonce + ";signature = " + signature);
            
            string[] arrTmp = { token, timestamp, nonce };
            Array.Sort(arrTmp);//字典排序
            string dev_signature = string.Join("", arrTmp);

            //sha1加密
            dev_signature = FormsAuthentication.HashPasswordForStoringInConfigFile(dev_signature, "SHA1").ToLower();


            return signature.Equals(dev_signature);
        }
    }
}
